home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / basic / pair.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  826 b   |  52 lines

  1. #include <LEDA/list.h>
  2.  
  3. class pair {
  4.  
  5.  double  x;
  6.  double  y;
  7.  
  8. public:
  9.  
  10. pair() { x = y = 0; }
  11. pair(const pair& p) { x = p.x; y = p.y; }
  12.  
  13. friend istream& operator>>(istream& is, pair& p)
  14. { return is >> p.x >> p.y; }
  15.  
  16. friend ostream& operator<<(ostream& os, const pair& p)
  17. { return os << p.x << " " << p.y; }
  18.  
  19. friend int compare(const pair&, const pair&);
  20.  
  21. };
  22.  
  23. void Print(const pair& p, ostream& out)  { out << p; } 
  24. void Read(pair& p, istream& in)  { in >> p; } 
  25.  
  26.  
  27. int    compare(const pair& p, const pair& q)
  28. {  if (p.x < q.x) return -1; 
  29.    if (p.x > q.x) return  1; 
  30.    if (p.y < q.y) return -1; 
  31.    if (p.y > q.y) return  1; 
  32.    return 0;  
  33. }
  34.  
  35.  
  36. #if !defined(__TEMPLATE_FUNCTIONS__)
  37. LEDA_TYPE_PARAMETER(pair)
  38. #endif
  39.  
  40.  
  41. main()
  42. {
  43.    list<pair> L;
  44.  
  45.    L.read("list of pairs: ");
  46.    L.sort();
  47.    L.print("sorted:\n",'\n');
  48.  
  49.  }
  50.  
  51.  
  52.